package main;


import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;

//生产逆向工程
public class Generator {

    //加载配置文件
    public void myBatisGenerator() throws Exception {
        ArrayList<String> warnings = new ArrayList<>();
        //读取配置文件
        File configFile = new File("./src/main/resources/generatorConfig.xml");
        ConfigurationParser parser = new ConfigurationParser(warnings);
        Configuration config = parser.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }


    public static void main(String[] args)  throws Exception {
        System.out.println("开始逆向工程");
        Generator generator = new Generator();
        generator.myBatisGenerator();
        System.out.println("结束逆向工程");
    }
}
